<%@page import="classes.Valuta"%>
<%@page import="models.Student"%>
<%@page import="models.Course"%>
<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%Course course = (Course) request.getAttribute("course");%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Course <%=course.getName()%></title>
        ${stylesheet}
        ${jquery}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>   
            <div class="content">
                <h1>Course <%=course.getName()%></h1>                
                
                <c:set var="check_enroled" value="false"/>
                <c:if test="${sessionScope.user != null}">                                    
                <c:if test="${sessionScope.userrole=='Administrator' || sessionScope.userrole=='Teacher'}">
                <c:set var="check_enroled" value="true"/>
                </c:if>
                <c:if test="${check_enroled==false}">
                <c:forEach items="${course.student}" var="student">                    
                    <c:if test="${student.id==sessionScope.user.member_id && check_enroled==false}">
                        <c:set var="check_enroled" value="true"/>
                    </c:if>                    
                </c:forEach>
                </c:if>                        
                </c:if>
                        <c:if test="${check_enroled==true}">
                        <div class="half-blocks">
                            <fieldset class="half-block">
                                <legend align="center"><div class="button no-link"><a>General</a></div></legend>
                                <div class="item">
                                    <a href="${url}CourseLesson?courseid=<%=course.getId()%>">Lessons</a>
                                </div>
                            </fieldset>
                            <fieldset class="half-block">
                                <legend align="center"><div class="button no-link"><a>Personal</a></div></legend>
                                <div class="item">
                                    <a href="AssignmentController/view?id=${course.id}">Assignments</a>
                                </div>
                                <div class="item">
                                    <a href="ViewQuiz?course=${course.id}">Quizzes</a>
                                </div>
                            </fieldset>
                        </div>
                        <!-- clear //-->
                        <div class="clear margin-bottom-10"></div>
                        <label>Description</label>
                        <div class="information-text">
                            <%=course.getDescription()%>
                        </div>                                                                                            
                        </c:if>
                        
                        <c:if test="${check_enroled==false}">
                        <div class="enroll">
                            <div class="padding-bottom-50"></div>
                            <div class="clear"></div>
                            <div class="enroll-block">
                                <label>Name</label>
                                <div class="information-text">
                                    <%=course.getName()%>
                                </div>
                                <label>Price</label>
                                <div class="information-text">
                                    <c:set var="price" value="${course.price}" />
                                    <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                    <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                </div>
                                <div class="left">
                                    <div class="button free-lesson"><a href="CourseLesson?courseid=${course.id}&isFree=true">Free lessons</a></div>
                                </div>
                                <div class="right">
                                    <div class="button"><a href="<c:choose><c:when test="${sessionScope.user == null}">Register</c:when><c:otherwise>CartController?courseid=${course.id}&redirect=true</c:otherwise></c:choose>">Enroll</a></div>
                                </div>
                            </div>                                    
                        </div>
                        </c:if>                        

            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
